import request from './index';

// 文件上传
export const uploadFileApi = async (file: File): Promise<any> => {
  const formData = new FormData();
  formData.append('file', file);
  try {
    return await request.post('/fileUpload', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  } catch (error) {
    console.error('文件上传失败:', error);
    throw error;
  }
};

// 文件下载
export const downloadFileApi = async (fileId: string): Promise<any> => {
  try {
    return await request.get(`/fileDownload/${fileId}`, {
      responseType: 'blob'
    });
  } catch (error) {
    console.error('文件下载失败:', error);
    throw error;
  }
};

